import request from '@/api/axios'
import {AxiosPromise} from 'axios'
import {DataRes} from '@/api/config'
import {BasePhysicalExamination} from './index'
import {Operation as Opr} from '@/components/dTable/dTable'

/**
 * @description: 表单属性
 * @return {*}
 */
export interface HospitalCourse extends BasePhysicalExamination {
  inDate?: Array<string> // 住院日期
  inStartDate?: string // 入院日期
  inEndDate?: string // 出院日期
  reason?: string // 原因
  unitsName?: string // 医疗机构名称
  caseNo?: string // 病案号
  styleSign?: number // 是否家庭病床史 - 0住院史，1家庭病床史
  operation?: Array<Opr>
}

/**
 * @description: 保存住院治疗情况
 * @param {HospitalCourse} data
 * @return {*}
 */
export const saveHospitalCourse = (data: Array<HospitalCourse>): AxiosPromise<DataRes<undefined>> => {
  return request({
    url: '/api/hospitalCourse/save',
    method: 'post',
    data
  })
}

/**
 * @description: 根据体检登记表id获取住院治疗情况数据
 * @param {{checkupRegisterId: string; styleSign?: string}} params //  checkupRegisterId 体检登记表id  styleSign 0住院史，1家庭病床史
 * @return {*}
 */
export const getHospitalCourse = (params: {checkupRegisterId: string; styleSign?: number}): AxiosPromise<DataRes<Array<HospitalCourse>>> => {
  return request({
    url: '/api/hospitalCourse/get',
    method: 'get',
    params
  })
}

/**
 * @description: 拒检住院治疗情况
 * @param {BasePhysicalExamination} data
 * @return {*}
 */
export const rejectHospitalCourse = (data: Array<BasePhysicalExamination>): AxiosPromise<DataRes<undefined>> => {
  return request({
    url: '/api/hospitalCourse/reject',
    method: 'post',
    data
  })
}
